<?php

namespace McUser\Model;
use Common\Model\CommonModel;

/*
 *  Copyright (c) 2014 The CCP project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
 *  that can be found in the LICENSE file in the root of the web site.
 *
 *   http://www.yuntongxun.com
 *
 *  An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

class WalletModel extends CommonModel {

	function _initialize(){}

	protected $trueTableName = 'k_user';

	/**
	 *	读出一个用户的剩余金额.
	 */
	public function read_rest_money($userID){
		$where['uid'] = $userID;

		$restMoney = $this -> where($where) -> getfield('money');		
		return $restMoney;
	}

	/*
	*	读取钱包信息
	*/
	public function read_wallet_info($userID){
		$where['userID'] = $userID;

		$data = $this -> where($where) -> order('ID desc') -> select();

		return $data[0];
	}


	/*
	*	提现完成后, 奖金额度要改变	
	*/
	public function apply_cash_opr($userID,$jinE,$tiXianID){
		$where['userID'] = $userID;

		$dataOld = $this -> where($where) -> select();

		/* dump( $dataOld ); */

		if ( count( $dataOld) > 0)
		{
			$data['tiXianAll'] = $dataOld[0]['tiXianAll'] + $jinE;
			$data['cashYuE'] = $dataOld[0]['cashYuE'] - $jinE;
			$data['lastTiXian'] = $jinE;
			$data['lastTiXianDate'] = date('Y-m-d H:i:s', time());
			$data['lastTiXianID'] = $tiXianID;

			$this -> where($where) -> save($data);
		}

	}
	
}